﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.IO;

public partial class Reports_ReportViewer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument report = new ReportDocument();
        report.Load(Server.MapPath("Roles.rpt"));

        //Set the location for the main report.
        SetTableLocation(report.Database.Tables);

        //Set the location for any of the subreports.
        foreach (ReportDocument rd in report.Subreports)
        {
            SetTableLocation(rd.Database.Tables);
        }

        report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "");
        
    }

    private void SetTableLocation(Tables tables)
    {
        ConnectionInfo connectionInfo = new ConnectionInfo();

        connectionInfo.ServerName = "VARALLO1";
        connectionInfo.DatabaseName = "HRPaidTimeOff";
        connectionInfo.UserID = "V2Application";
        connectionInfo.Password = "wrox";

        foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
        {
            TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
            tableLogOnInfo.ConnectionInfo = connectionInfo;
            table.ApplyLogOnInfo(tableLogOnInfo);
        }
    }
}
